<?php
namespace app\index\controller;

class Index extends Common
{
    public function index()
    {   
        $banner=$this->getBanner();// banner
        $wm=$this->getAbout();// 关于我们
        $works=$this->getZuopin(); // 摄影作品
        $coop=$this->getCoop();// 合作伙伴
        $this->assign(array(
            'banner'   =>$banner,
            'wm'       =>$wm,
            'works'    =>$works,
            'coop'     =>$coop,
        ));
        return view();
    }
    // 获取banner
    private function getBanner(){
        // 首页banner
        $banner=db('banner')->where('isshow',1)->select();
        return $banner;
    }
    // 获取关于我们
    private function getAbout(){
        $about=db('category')->field('content')->where('id',16)->find();
        return $about;
    }
    // 获取摄影作品
    private function getZuopin(){
        $cate=db('category')->where('pid',20)->field('id,cate_name')->select();
        foreach ($cate as $k => $v) {
            $list=db('article')->alias('a')
                  ->join('pic p','p.aid=a.id')
                  ->where('a.cid',$v['id'])
                  ->where('a.istop',1)
                  ->field('a.title,p.pic,a.id')
                  ->select();
            $cate[$k]['art']=$list;
        }
        return $cate;
    }
    // 获取合作伙伴
    private  function getCoop()
    {
        $coop=db('article')->alias('a')
        ->join('pic p','p.aid=a.id')
        ->where('a.cid',36)
        ->where('a.istop',1)
        ->field('a.title,p.pic,a.id')
        ->select();
        return $coop;
    }
}
